package com.changanw.dd.service;

import com.changanw.dd.Mapper.MasterMapper;
import com.changanw.dd.Mapper.SlaveMapper;
import com.changanw.dd.Mapper.UserMapper;
import com.changanw.dd.annotation.DataSource;
import com.changanw.dd.model.User;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class UserService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    MasterService masterService;
    @Autowired
    SlavService slavService;

    //@DataSource("slave")
    public List<User> getAllUser(){
        return userMapper.getAllUser();
    }

    @GlobalTransactional
    public void test() {
        masterService.updateUserAge("张三",20);
        slavService.updateUserAge("李四", 20);
    }
}
